package com.wanxi.control.util;

import java.sql.*;

public class JDBC {
    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取连接
     * @return
     */
    private Connection getConnection(){
        String url = "jdbc:mysql://localhost:3306/lawyer_firm?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT" ;
        String user = "root";
        String password = "";
        Connection connection = null;
        try {
            connection = DriverManager.getConnection(url,user,password);
        } catch (SQLException e) {
            System.out.println(e.getErrorCode());
            e.printStackTrace();
        }
        return connection;
    }

private ResultSet query(String sql){
        Connection connection = getConnection();
    try {
        PreparedStatement preparedStatement =connection.prepareStatement(sql);

        ResultSet resultSet = preparedStatement.executeQuery();
        return resultSet;
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return null;
}

}
